{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "test=pd.read_csv('test.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "train=pd.read_csv('train.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(33177270, 4)\n",
      "   uid  iid  score  time\n",
      "0    0    0      2    19\n",
      "1    0    8      4   273\n",
      "2    0   13      1   587\n",
      "3    0   18      3    15\n",
      "4    0   34      3    17\n",
      "             uid    iid  score  time\n",
      "33177265  223969  12729      2  1346\n",
      "33177266  223969  12983      1  1346\n",
      "33177267  223969  13000      4  1346\n",
      "33177268  223969  13291      3  1346\n",
      "33177269  223969  13531      4  1346\n"
     ]
    }
   ],
   "source": [
    "print train.shape\n",
    "print train.head()\n",
    "print train.tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "user=train['uid']\n",
    "item=train['iid']\n",
    "score=train['score']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "user = user.drop_duplicates()  \n",
    "item = item.drop_duplicates()\n",
    "score = score.drop_duplicates()  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(157949L,)\n",
      "(14620L,)\n",
      "(5L,)\n"
     ]
    }
   ],
   "source": [
    "print user.shape\n",
    "print item.shape\n",
    "print score.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "train2=train.loc[:,['uid','iid','score']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "train2.to_csv('train2.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>uid</th>\n",
       "      <th>iid</th>\n",
       "      <th>score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>3.317727e+07</td>\n",
       "      <td>3.317727e+07</td>\n",
       "      <td>3.317727e+07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>8.481261e+04</td>\n",
       "      <td>5.109407e+03</td>\n",
       "      <td>3.495277e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>6.057698e+04</td>\n",
       "      <td>3.616496e+03</td>\n",
       "      <td>1.088213e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>3.136900e+04</td>\n",
       "      <td>1.993000e+03</td>\n",
       "      <td>3.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>7.584700e+04</td>\n",
       "      <td>4.417000e+03</td>\n",
       "      <td>4.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>1.314850e+05</td>\n",
       "      <td>8.039000e+03</td>\n",
       "      <td>4.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>2.239690e+05</td>\n",
       "      <td>1.472500e+04</td>\n",
       "      <td>5.000000e+00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                uid           iid         score\n",
       "count  3.317727e+07  3.317727e+07  3.317727e+07\n",
       "mean   8.481261e+04  5.109407e+03  3.495277e+00\n",
       "std    6.057698e+04  3.616496e+03  1.088213e+00\n",
       "min    0.000000e+00  0.000000e+00  1.000000e+00\n",
       "25%    3.136900e+04  1.993000e+03  3.000000e+00\n",
       "50%    7.584700e+04  4.417000e+03  4.000000e+00\n",
       "75%    1.314850e+05  8.039000e+03  4.000000e+00\n",
       "max    2.239690e+05  1.472500e+04  5.000000e+00"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train2.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "uid      0\n",
      "iid      0\n",
      "score    2\n",
      "Name: 0, dtype: int64\n",
      "uid      0\n",
      "iid      8\n",
      "score    4\n",
      "Name: 1, dtype: int64\n",
      "uid       0\n",
      "iid      13\n",
      "score     1\n",
      "Name: 2, dtype: int64\n",
      "uid       0\n",
      "iid      18\n",
      "score     3\n",
      "Name: 3, dtype: int64\n",
      "uid       0\n",
      "iid      34\n",
      "score     3\n",
      "Name: 4, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "train3=train2.head()\n",
    "for index, row in train3.iterrows():\n",
    "    print row"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>uid</th>\n",
       "      <th>iid</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>12960</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>12726</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>11463</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>10739</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>3441</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>1</td>\n",
       "      <td>301</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>1</td>\n",
       "      <td>13291</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>1</td>\n",
       "      <td>2814</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>1</td>\n",
       "      <td>2857</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2</td>\n",
       "      <td>12860</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>2</td>\n",
       "      <td>11091</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>2</td>\n",
       "      <td>13057</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>3</td>\n",
       "      <td>8992</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>3</td>\n",
       "      <td>11082</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>3</td>\n",
       "      <td>2665</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>3</td>\n",
       "      <td>12570</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>3</td>\n",
       "      <td>13410</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>3</td>\n",
       "      <td>12714</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>3</td>\n",
       "      <td>14649</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>3</td>\n",
       "      <td>2635</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>4</td>\n",
       "      <td>14339</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>4</td>\n",
       "      <td>13000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>5</td>\n",
       "      <td>1326</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>5</td>\n",
       "      <td>2308</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>5</td>\n",
       "      <td>1934</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>5</td>\n",
       "      <td>2405</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>5</td>\n",
       "      <td>13509</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>5</td>\n",
       "      <td>12362</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>5</td>\n",
       "      <td>7636</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>5</td>\n",
       "      <td>5155</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>546166</th>\n",
       "      <td>223267</td>\n",
       "      <td>12181</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>546167</th>\n",
       "      <td>223267</td>\n",
       "      <td>3569</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>546168</th>\n",
       "      <td>223277</td>\n",
       "      <td>11865</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>546169</th>\n",
       "      <td>223686</td>\n",
       "      <td>12983</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>546170</th>\n",
       "      <td>223842</td>\n",
       "      <td>1801</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>546171</th>\n",
       "      <td>223842</td>\n",
       "      <td>1418</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>546172</th>\n",
       "      <td>223842</td>\n",
       "      <td>146</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>546173</th>\n",
       "      <td>223842</td>\n",
       "      <td>3033</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>546174</th>\n",
       "      <td>223842</td>\n",
       "      <td>282</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>546175</th>\n",
       "      <td>223842</td>\n",
       "      <td>2883</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>546176</th>\n",
       "      <td>223842</td>\n",
       "      <td>2161</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>546177</th>\n",
       "      <td>223842</td>\n",
       "      <td>10018</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>546178</th>\n",
       "      <td>223842</td>\n",
       "      <td>11218</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>546179</th>\n",
       "      <td>223842</td>\n",
       "      <td>4753</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>546180</th>\n",
       "      <td>223842</td>\n",
       "      <td>9687</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>546181</th>\n",
       "      <td>223842</td>\n",
       "      <td>1321</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>546182</th>\n",
       "      <td>223842</td>\n",
       "      <td>601</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>546183</th>\n",
       "      <td>223842</td>\n",
       "      <td>1340</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>546184</th>\n",
       "      <td>223842</td>\n",
       "      <td>1335</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>546185</th>\n",
       "      <td>223842</td>\n",
       "      <td>3428</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>546186</th>\n",
       "      <td>223842</td>\n",
       "      <td>6155</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>546187</th>\n",
       "      <td>223842</td>\n",
       "      <td>4664</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>546188</th>\n",
       "      <td>223842</td>\n",
       "      <td>2918</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>546189</th>\n",
       "      <td>223842</td>\n",
       "      <td>6607</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>546190</th>\n",
       "      <td>223842</td>\n",
       "      <td>3576</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>546191</th>\n",
       "      <td>223842</td>\n",
       "      <td>7033</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>546192</th>\n",
       "      <td>223842</td>\n",
       "      <td>2391</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>546193</th>\n",
       "      <td>223842</td>\n",
       "      <td>2625</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>546194</th>\n",
       "      <td>223842</td>\n",
       "      <td>6477</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>546195</th>\n",
       "      <td>223969</td>\n",
       "      <td>9758</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>546196 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "           uid    iid\n",
       "0            0  12960\n",
       "1            1  12726\n",
       "2            1  11463\n",
       "3            1  10739\n",
       "4            1   3441\n",
       "5            1    301\n",
       "6            1  13291\n",
       "7            1   2814\n",
       "8            1   2857\n",
       "9            2  12860\n",
       "10           2  11091\n",
       "11           2  13057\n",
       "12           3   8992\n",
       "13           3  11082\n",
       "14           3   2665\n",
       "15           3  12570\n",
       "16           3  13410\n",
       "17           3  12714\n",
       "18           3  14649\n",
       "19           3   2635\n",
       "20           4  14339\n",
       "21           4  13000\n",
       "22           5   1326\n",
       "23           5   2308\n",
       "24           5   1934\n",
       "25           5   2405\n",
       "26           5  13509\n",
       "27           5  12362\n",
       "28           5   7636\n",
       "29           5   5155\n",
       "...        ...    ...\n",
       "546166  223267  12181\n",
       "546167  223267   3569\n",
       "546168  223277  11865\n",
       "546169  223686  12983\n",
       "546170  223842   1801\n",
       "546171  223842   1418\n",
       "546172  223842    146\n",
       "546173  223842   3033\n",
       "546174  223842    282\n",
       "546175  223842   2883\n",
       "546176  223842   2161\n",
       "546177  223842  10018\n",
       "546178  223842  11218\n",
       "546179  223842   4753\n",
       "546180  223842   9687\n",
       "546181  223842   1321\n",
       "546182  223842    601\n",
       "546183  223842   1340\n",
       "546184  223842   1335\n",
       "546185  223842   3428\n",
       "546186  223842   6155\n",
       "546187  223842   4664\n",
       "546188  223842   2918\n",
       "546189  223842   6607\n",
       "546190  223842   3576\n",
       "546191  223842   7033\n",
       "546192  223842   2391\n",
       "546193  223842   2625\n",
       "546194  223842   6477\n",
       "546195  223969   9758\n",
       "\n",
       "[546196 rows x 2 columns]"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test="
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [Root]",
   "language": "python",
   "name": "Python [Root]"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
